"""程序主入口"""
import time
from core import adb_utils, device_manager, ocr_processor
from utils import logger

def main():
    """主控制流程"""
    log = logger.get_logger("Main")
    
    try:
        # 初始化ADB工具
        adb = adb_utils.ADBUtils()
        
        # 获取已连接设备
        devices = adb.get_connected_devices()
        
        if not devices:
            log.warning("未检测到已授权的ADB设备")
            log.info("解决方案：请开启USB调试并在手机上授权电脑")
            return
            
        log.info(f"检测到 {len(devices)} 台设备: {', '.join(devices)}")
        
        # 初始化OCR处理器
        ocr_engine = ocr_processor.OCRProcessor(use_gpu=False)
        
        # 初始化设备处理器
        device_processor = device_manager.DeviceProcessor(
            ocr_engine, 
            app_name="App1"  # 可配置为App1或App2
        )
        
        # 依次处理每台设备
        for device_id in devices:
            device_processor.process_device(device_id)
            time.sleep(1)  # 设备间处理间隔
            
    except Exception as e:
        log.exception(f"主程序错误: {str(e)}")

if __name__ == "__main__":
    main()